/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn;

import java.io.File;

/**
 * <p>Project: app2022 - Str4
 * <p>Powered by webrx On 2022-01-12 15:38:04
 *
* @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Str4 {
    public static void main(String[] args) {
        String f = "c:/users/java/img/abc.jpg";
        System.out.println(f);

        //查找索引
        System.out.println("abcjava-myjava".indexOf("java"));//3
        System.out.println("abcjava-myjava".indexOf("java",6));//10
        System.out.println("abcjava-myjava".indexOf("mysql"));//-1
        System.out.println("abcjava-myjava".lastIndexOf("java"));//10

        System.out.println("abcjava-myjava".lastIndexOf("mysql"));//-1
        System.out.println("abcjava-myjava".contains("java"));//true
        System.out.println("abcjava-myjava".startsWith("java"));//false
        System.out.println("abcjava-myjava".endsWith("java"));//true


        //trim() 清除左 右连续的空格
        System.out.println("   hello java   ".length());//16
        System.out.println("   hello java   ".trim().length());//10

        //查找并替换全部
        System.out.println(" hello             java     ".replace(" ",""));//hellojava

        //截取
        var s1 = f.substring(6);
        System.out.println(s1);//rs/java/img/abc.jpg
        var s2 = f.substring(6,10);
        System.out.println(s2);//rs/j

        //扩展名
        //var ext = f.substring(f.lastIndexOf(".")+1).toLowerCase(); jpg
        var ext = f.substring(f.lastIndexOf(".")).toLowerCase();//.jpg
        System.out.println(ext);
        //文件名 abc.jpg
        System.out.println(f.substring(f.lastIndexOf("/")+1));//abc.jpg

        //文件基本名 abc
        System.out.println(f.substring(f.lastIndexOf("/")+1,f.lastIndexOf(".")));

        //文件的目录 c:/users/java/img/
        System.out.println(f.substring(0,f.lastIndexOf("/")+1));

        //项目常见的问题  linux /usr/local/home/abc.jpg  windows d:\\user\\abc\\xxxxxx.jpg

        System.out.println(File.separator);//windows \  linux /

        String ff = "d:\\user\\abcc\\y.jpg";
        System.out.println(ff.contains("\\"));//true
        System.out.println(ff.contains("/"));//false
        System.out.println(ff.substring(ff.lastIndexOf("\\")+1));
    }
}
